package com.yus.service;

import com.yus.domain.Girl;
import com.yus.repository.GirlRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class GirlService {

    @Autowired
    private GirlRepository girlRepository;

    @Transactional
    public void insertTwo() {
        Girl girlA = new Girl();
        girlA.setName("Joyce");
        girlA.setAge(18);
        girlRepository.save(girlA);

        Girl girlB = new Girl();
        girlB.setName("Alice");
        girlB.setAge(20);
        girlRepository.save(girlB);
    }

    public void getAge(Integer id) throws Exception {
        Girl girl = girlRepository.findOne(id);
        Integer age = girl.getAge();
        if (age < 10) {
            //返回"你可能还在上小学"
            throw new Exception("你可能还在上小学");
        } else if (age < 16) {
            //返回"你可能在上初中"
            throw new Exception("你可能在上初中");
        }
    }
}